
<template>
 <div>
  <el-table
    :data="tableData"
   
    style="width: 100%">
    <el-table-column
      label="Date"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.date }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="Name"
      width="180">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>Name: {{ scope.row.name }}</p>
          <p>Addr: {{ scope.row.address }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.name }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column  
      
      label="Operations">
      <template slot-scope="scope">
        <el-button 
        :disabled="scope.row.omg"
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">{{ scope.row.btnLable}}</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
      </template>
    </el-table-column>
  </el-table>
   <el-button type="info" :disabled="exitBasc"  @click="handleTotalEdit()">{{totalBtnLable}}</el-button>
 </div>

</template>

<script>
  export default {
    data() {
      return {
        tableData: [{
          date: '2016-05-03',
          name: 'Tom',
          address: 'No. 189, Grove St, Los Angeles',
          omg:false,
          btnLable:"修改"
        }, {
          date: '2016-05-02',
          name: 'Tom',
          address: 'No. 189, Grove St, Los Angeles',
           omg:false,
            btnLable:"修改"
        }, {
          date: '2016-05-04',
          name: 'Tom',
          address: 'No. 189, Grove St, Los Angeles',
           omg:false,
            btnLable:"修改"
        }, {
          date: '2016-05-01',
          name: 'Tom',
          address: 'No. 189, Grove St, Los Angeles',
          omg:false,
           btnLable:"修改"
        }],
        exitBasc:false,
        totalBtnLable:"修改"
      }
    },
    methods: {
      handleEdit(index, row) {
        console.log(index, row);
        if(row.btnLable === "修改"){
          this.exitBasc =true
       }else{
          this.exitBasc =false
       }
      this.tableData.forEach((column,key)=>{
       if(index===key){
           if(row.btnLable === "保存"){
                column.btnLable = "修改"
              }else{
                 column.btnLable = "保存"
              }

       }else{
          if(column.omg === true){
              column.omg= false
          }else{
              column.omg=true
          }
       }
       
      })
     
      },
      handleDelete(index, row) {
        console.log(index, row);
      },
      handleTotalEdit(){
        if(this.totalBtnLable ==="保存"){
            this.tableData.forEach((column,key)=>{
              column.omg=false
            return
          })
           this.totalBtnLable ="修改"
        }else{
          this.tableData.forEach((column,key)=>{
           column.omg=true
          return
            })
             this.totalBtnLable ="保存"
        }
        
     
      }
    }
  }
</script>





